package while_lang;

import java.io.*;

import while_lang.ast.*;
import while_lang.parser.ParserCup;
import while_lang.semantics.State;
import while_lang.semantics.SymbolTable;

public class Test {

	public static void main(String[] args) throws Exception {
		System.out.println("Welcome to the While++ interpreter console.");
		System.out.println("Type your code and two enters to evaluate.");
		System.out.println();
		StringBuilder code = new StringBuilder();
		//State state = new State();
		SymbolTable table = new SymbolTable();
		Stmt stmt;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for (String line = in.readLine(); line != null; line = in.readLine()) {
			if (line.length() > 0) {
				code.append(line +'\n');
			} else if (code.length() > 0) {
				try {
					stmt = ParserCup.parseString(code.toString());
					table = stmt.checkTypes(table);
					System.out.println("Tabla: "+ table +"\n");
					for (String str : table.errors){
						System.out.println("Error: "+ str);
					}
				} catch (Throwable error) {
					error.printStackTrace(System.err);
				}
				code = new StringBuilder();
			} else {
				System.out.println("Exiting.");
				break; // Exit.
			}		
		}
	}
}
